﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.MFG.PRD.App.ReportPlugIn.MonthReport;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiMinCRMPlugin
{
    [Description("生产入库月报")]
    [HotUpdate]
    public class InStockMonthEdit : InStockMonthRpt
    {
        private string CostCalBilltTableNames;
        public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
        {
            IDBService dbService = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();
            CostCalBilltTableNames = dbService.CreateTemporaryTableName(this.Context);
            base.BuilderReportSqlAndTempTable(filter, CostCalBilltTableNames);
            DynamicObject customFilter = filter.FilterParameter.CustomFilter;
            string sql = string.Format(@"select A.*,C.FDATAVALUE INTO {0} from {1} A
                                LEFT JOIN T_BD_MATERIAL B ON A.FPRODNUM = B.FNUMBER AND A.FMATERIALID=B.FMATERIALID
                                LEFT JOIN T_BAS_ASSISTANTDATAENTRY_L C ON B.F_SVZW_ASSISTANT_QTR_CA9 = C.FENTRYID ", tableName, CostCalBilltTableNames);
            DBUtils.Execute(this.Context, sql.ToString());

        }
        public override ReportHeader GetReportHeaders(IRptParams filter)
        {
            ReportHeader report = base.GetReportHeaders(filter);
            report.AddChild("FDATAVALUE", new Kingdee.BOS.LocaleValue("剂型", this.Context.UserLocale.LCID));
            return report;
        }

        public override void CloseReport()
        {
            base.CloseReport();
            if (!string.IsNullOrEmpty(CostCalBilltTableNames))
            {
                IDBService dbService = Kingdee.BOS.App.ServiceHelper.GetService<IDBService>();

                dbService.DeleteTemporaryTableName(this.Context, new string[1] { CostCalBilltTableNames });
            }
        }
    }
}
